package org.mozhu.mboot.backend.system.account.service;

import org.mozhu.mboot.backend.system.account.entity.User;
import org.mozhu.mboot.backend.system.account.repository.UserRepository;
import org.mozhu.mboot.common.data.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 用户 - 业务层实现类
 *
 * @author mozhu
 */
@Transactional
@Service
public class UserServiceImpl extends BaseService<User, Long> implements UserService {

    @Autowired
    PasswordEncoder passwordEncoder;

    @Autowired
    UserRepository userRepository;

    @Override
    public User findByLoginName(String loginName) {
        return userRepository.findByLoginName(loginName);
    }

    @Override
    public boolean isValidPassword(User user, String plainPassword) {
        return passwordEncoder.matches(plainPassword, user.getPassword());
    }

}
